package org.dubnation.base.excel.upload.dto;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelEntity;
import cn.afterturn.easypoi.excel.annotation.ExcelIgnore;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dubnation.base.annotation.SexJustManAndWoman;
import org.dubnation.base.excel.upload.util.ExcelVerify;
import org.springframework.stereotype.Component;

import javax.validation.constraints.*;
import java.io.Serializable;

/**
 * 导入的实体类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@ExcelTarget(value = "employee")
public class EmployeeDTO extends ExcelVerify implements Serializable {

    @ExcelIgnore
    @Excel(name = "编号")
    private Long id;

    @NotBlank(message = "用户名不能为空")
    @Excel(name = "用户名")
    private String username;

    /**
     * 真实姓名
     */
    @NotBlank(message = "真实姓名不能为空")
    @Excel(name = "真实姓名")
    @Pattern(regexp = "^[\u4e00-\u9fa5]{2,4}$", message = "姓名一般为2-4个字")
    private String realName;

    @NotBlank(message = "邮箱不能为空")
    @Email(regexp = "\\w+@\\w+(\\.\\w{2,3})*\\.\\w{2,3}", message = "邮箱格式不正确")
    @Excel(name = "邮箱")
    private String email;

    @NotBlank(message = "电话号码不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$",
            message = "电话号码格式不正确")
    @Excel(name = "电话号码")
    private String phone;

    @NotBlank(message = "密码不能为空")
    @Size(min = 4, max = 6, message = "密码为4-6位数")
    @Excel(name = "密码")
    private String password;

    @ExcelIgnore
    private String confirmPassword;

    @DecimalMin(value = "18", message = "年龄不能小于18")
    @DecimalMax(value = "60", message = "年龄不能大于60")
    @Excel(name = "年龄")
    private Integer age;

    @NotBlank(message = "性别不能为空")
    @SexJustManAndWoman(message = "性别只限于男女")
    @Excel(name = "性别", replace = {"男_1", "女_0"})
    private String sex;

    /**
     * 1=正常 2=锁定 3=注销
     */
    @Excel(name = "状态", replace = {"正常_1", "锁定_2", "注销_3"})
    private String state;

    /**
     * 所属部门
     */
    @ExcelEntity(id = "departmentDTO")
    private DepartmentDTO departmentDTO;
}
